package conversion.mapper;


import conversion.bean.Plugin;
import org.apache.ibatis.annotations.*;

import java.util.List;


/**
 * 插件实体化的mapper接口，用于数据库操作
 */
@Mapper
public interface PluginMapper {

        @Insert("INSERT INTO plugins (plugin_name, plugin_path, is_load) " +
                "VALUES (#{pluginName}, #{pluginPath}, #{isLoad})")
        @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
        void insertPlugin(Plugin plugin);

        @Select("SELECT * FROM plugins WHERE id = #{id}")
        Plugin getPluginById(Integer id);

        @Select("SELECT * FROM plugins WHERE plugin_name LIKE CONCAT('%', #{pluginName}, '%')")
        List<Plugin> getPluginByValue(String searchValue);

        @Update("UPDATE plugins SET is_load = #{isLoad} WHERE id = #{id}")
        void updatePluginLoadStatus(@Param("id") Integer id, @Param("isLoad") Boolean isLoad);

        @Delete("DELETE FROM plugins WHERE id = #{id}")
        void deletePlugin(Integer id);

        @Select("SELECT * FROM plugins WHERE is_load = #{isLoad}")
        List<Plugin> getPluginsByLoadStatus(Boolean isLoad);

        @Select("SELECT * FROM plugins")
        List<Plugin> getAllPlugins();

}
